package com.rxmvp.rxjavademo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.rxmvp.rxjavademo.RxRetrofit.Response.BaseResponse;
import com.rxmvp.rxjavademo.RxRetrofit.RxRetrofitUtils;
import com.rxmvp.rxjavademo.bean.NewsBean;

import java.util.List;

import rx.Subscriber;

public class RxRetrofitActivity extends AppCompatActivity {

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rx_retrofit);
        textView = (TextView) findViewById(R.id.tv_json);
    }

    public void getData(View view) {
        RxRetrofitUtils.initObservable(App.getService().getJson1("top", "004a2b29ab3245fdfb95ed25e590cc2b"))
            .subscribe(new Subscriber<BaseResponse<NewsBean>>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    Log.e("tag", e.getMessage());
                }

                @Override
                public void onNext(BaseResponse<NewsBean> newsBeanBaseResponse) {
                    List<NewsBean> newsBeans = newsBeanBaseResponse.getResult().getData();
                    textView.setText(newsBeans.get(0).toString());
                }
            });
    }
}
